package com.example.dialog;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (Intent.ACTION_BATTERY_LOW.equals(intent.getAction())) {
            // 处理电池低的情况
            Toast.makeText(context, "电池电量低，请充电！", Toast.LENGTH_LONG).show();
        } else if (action.equals("myAction")) {
//            Toast.makeText(context, "接收到广播（动态注册）", Toast.LENGTH_SHORT).show();
            if (Intent.ACTION_BATTERY_LOW.equals(intent.getAction())) {
                // 处理电池低的情况
                Toast.makeText(context, "电池电量低，请充电！", Toast.LENGTH_LONG).show();
            }
            else{
                Toast.makeText(context, "电池电量充足！", Toast.LENGTH_LONG).show();
            }
        } else if (action.equals("myAction_static")) {
            Toast.makeText(context, "接收到广播（静态注册）", Toast.LENGTH_SHORT).show();
        }
    }
}